<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * 首页广告
 * @author weihu
 *
 */
class Ad extends MY_Controller {

	public function __construct()
    {
        parent::__construct();
    }
    
    //预约模特
    public function processModel()
    {
        $this->load->view('ad/processmodel');
    }
    
    //问答列表
    public function faq()
    {
        $type = $_GET['type'];
        if (empty($type))
            $type = 1;
        $this->load->model('Faq_model');
        $faqList = $this->Faq_model->get_list(array('type'=>$type),'question,answer','id desc');
        $result = array(
            'list' => $faqList,
            'type' => $type
        );
        
        $this->load->view('ad/faq', $result);
    }
    
    //魔步网是什么
    public function whatMobooker()
    {
        $this->load->view('ad/whatmobooker');
    }
    
    //为什么找魔步网
    public function whyMobooker()
    {
        $this->load->view('ad/whymobooker');
    }
    
    //时尚资讯
    public function advisory()
    {
        $page = _get_page();
        $pagesize = 3; // 每页大小
        $arrParam = array();
        $arrWhere = array('type'=>1);
        $orderby = 'advisory_date desc';
        
        $this->load->model('Advisory_model');
        $list = $this->Advisory_model->fetch_page($page, $pagesize, $arrWhere, 'id,title,content,advisory_img,advisory_date,tag', $orderby);
        //echo $this->User_model->db->last_query();die;
        
        // 分页
        $pagecfg = array();
        $pagecfg['base_url'] = _create_url('ad/advisory', $arrParam);
        $pagecfg['total_rows'] = $list['count'];
        $pagecfg['cur_page'] = $page;
        $pagecfg['per_page'] = $pagesize;
        $this->pagination->initialize($pagecfg);
        $list['pages'] = $this->pagination->create_links();
        
        $result = array(
            'list' => $list,
            'arrParam' => $arrParam,
            'pagesize' => $pagesize
        );
        
        $this->load->view('ad/advisory', $result);
    }
    
    //资讯详情
    public function advisorydesc()
    {
        $id	= _get_key_val($this->input->get('id'), TRUE);
        $advisory_desc = '';
        $title = '';
        $next_id = 0;
        $next_title = '';
        $pre_id = 0;
        $pre_title = '';
        if ($id)
        {
            $this->load->model('Advisory_model');
            $advisory = $this->Advisory_model->get_by_id($id,'advisory_desc,title');
            $advisory_desc = $advisory['advisory_desc']?$advisory['advisory_desc']:'';
            $title = $advisory['title']?$advisory['title']:'';
            $next = $this->Advisory_model->get_by_where('id > '.$id,'MIN(id) as id,title');
            $next_id = $next['id']?$next['id']:0;
            $next_title = $next['title']?$next['title']:'';
            $pre = $this->Advisory_model->get_by_where('id < '.$id,'MAX(id) as id,title');
            $pre_id = $pre['id']?$pre['id']:0;
            $pre_title = $pre['title']?$pre['title']:'';
        }
        $result = array(
            'title' => $title,
            'advisory_desc' => $advisory_desc,
            'next_id' => $next_id,
            'next_title' => $next_title,
            'pre_id' => $pre_id,
            'pre_title' => $pre_title
        );
        
        $this->load->view('ad/advisorydesc',$result);
    }
    
    //摄影基地
    public function photography()
    {
        $page = _get_page();
        $pagesize = 2; // 每页大小
        $arrParam = array();
        $arrWhere = array('type'=>2);
        $orderby = 'advisory_date desc';
    
        $this->load->model('Advisory_model');
        $list = $this->Advisory_model->fetch_page($page, $pagesize, $arrWhere, 'id,title,content,advisory_img,advisory_date,tag', $orderby);
        //echo $this->User_model->db->last_query();die;
    
        // 分页
        $pagecfg = array();
        $pagecfg['base_url'] = _create_url('ad/photography', $arrParam);
        $pagecfg['total_rows'] = $list['count'];
        $pagecfg['cur_page'] = $page;
        $pagecfg['per_page'] = $pagesize;
        $this->pagination->initialize($pagecfg);
        $list['pages'] = $this->pagination->create_links();
    
        $result = array(
            'list' => $list,
            'arrParam' => $arrParam,
            'pagesize' => $pagesize
        );
    
        $this->load->view('ad/photography', $result);
    }
    
    //摄影基地详情
    public function photodesc()
    {
        $id	= _get_key_val($this->input->get('id'), TRUE);
        $this->load->model('Advisory_model');
        $photo = $this->Advisory_model->get_by_id($id,'advisory_desc');
        //最新推荐
        $recommend_photo = $this->Advisory_model->get_list(array('is_recommend'=>1,'type'=>2),'title,advisory_img,id','update_time desc',4);
        $result = array(
            'photo' => $photo,
            'recommend_photo' => $recommend_photo
        );
        
        $this->load->view('ad/photodesc', $result);
    }
}